/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef SWANLINK_FINANCE_INNERKITS_ICCREADER_SRV_CLIENT_H_
#define SWANLINK_FINANCE_INNERKITS_ICCREADER_SRV_CLIENT_H_

#include <singleton.h>
#include <memory>
#include <mutex>
#include "iremote_object.h"
#include "iiccreader_srv.h"
#include "cashdevice_client.h"

namespace SwanLink {
namespace Finance {
class IccreaderSrvClient final : public DelayedRefSingleton<IccreaderSrvClient>, public CashDeviceClient {
    DECLARE_DELAYED_REF_SINGLETON(IccreaderSrvClient)

 public:
    DISALLOW_COPY_AND_MOVE(IccreaderSrvClient);

   
    /**
     * 获取设备信息
     */
    int GetDeviceInfo(int fd,DeviceInfo &devInfo);
    /**
     * IO控制
     */
    int IccIOCtrl(int fd,IOType type,int value);
    /**
     * cpu命令
     */
    int ApduCommand(int fd,IOType type,int len,uint8_t cmd[],uint8_t cmd_out[]);
    /**
     * 寻卡
     */
    int CardSearch(int fd,int timeout,SearchResult *result);
    /**
     * 停止寻卡
     */
    int CardStopSearch(int fd);
    /**
     * 激活非存储卡
     */
    int RfCardActive(int fd,RfCardInfo &cardInfo);
    /**
     * 非存储卡休眠
     */
    int RfCardDormancy(int fd);
    /**
     * 扫描数据
     */
    int ScanData(int fd,const DeviceConfig& config,ResultData &result);


 private:
    class IccreaderSrvDeathRecipient : public IRemoteObject::DeathRecipient {
     public:
        IccreaderSrvDeathRecipient() = default;
        ~IccreaderSrvDeathRecipient() = default;
        void OnRemoteDied(const wptr<IRemoteObject>& remote);
     private:
        DISALLOW_COPY_AND_MOVE(IccreaderSrvDeathRecipient);
    };

    ErrCode Connect();
    sptr<ICashDeviceSrv> Proxy() {return proxy_;};
    sptr<IIccreaderSrv> proxy_ {nullptr};
    sptr<IRemoteObject::DeathRecipient> deathRecipient_ {nullptr};
    void ResetProxy(const wptr<IRemoteObject>& remote);
    std::mutex mutex_;
};
} // namespace Finance
} // namespace SwanLink

#endif // SWANLINK_FINANCE_INNERKITS_ICCREADER_SRV_CLIENT_H_
